package com.lagou.service.impl;

import com.lagou.dao.PositionDao;
import com.lagou.dao.PositionDetailDao;
import com.lagou.pojo.Position;
import com.lagou.pojo.PositionDetail;
import com.lagou.service.TransactionService;
import org.apache.shardingsphere.transaction.annotation.ShardingTransactionType;
import org.apache.shardingsphere.transaction.core.TransactionType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Deprecated
@Service
@Transactional
@ShardingTransactionType(TransactionType.XA)
public class TransactionServiceImpl implements TransactionService {
	@Autowired
	private PositionDao positionDao;
	@Autowired
	private PositionDetailDao positionDetailDao;

	@Override
	public void addPositionAndPositionDetail() {
		for (long i = 1; i <= 3; i++) {
			Position position = new Position();
			position.setName("lagou" + i);
			position.setSalary("100000");
			position.setCity("北京");
			positionDao.save(position);

			if (i == 3) {
				int a = 1 / 0;
			}

			PositionDetail positionDetail = new PositionDetail();
			positionDetail.setPid(position.getId());
			positionDetail.setDescription("职位明细" + i);
			positionDetailDao.save(positionDetail);
		}
	}
}
